package com.spzx.order.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.order.domain.OrderForm;
import com.spzx.order.domain.OrderInfo;
import com.spzx.order.domain.TradeVo;
import com.spzx.order.service.IOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("orderInfo")
public class OrderInfoController {
    @Autowired
    IOrderInfoService orderInfoService;
    // 获取购物车信息，交易码和总价
    @GetMapping("trade")
    public AjaxResult trade(){
        TradeVo tradeVo = orderInfoService.trade();
        return AjaxResult.success(tradeVo);
    }

    //提交订单
    @PostMapping("submitOrder")
    public AjaxResult submitOrder(@RequestBody OrderForm orderForm){
        Long productId = orderInfoService.submitOrder(orderForm);
        return AjaxResult.success(productId);
    }


    // 支付页面获取订单信息
    @GetMapping("getOrderInfo/{orderId}")
    public AjaxResult  getOrderInfo(@PathVariable("orderId") Long orderId){
        OrderInfo orderInfo = orderInfoService.getById(orderId);
        return AjaxResult.success(orderInfo);
    }

    @Operation(summary = "根据订单号获取订单信息")
    @InnerAuth
    @GetMapping("getByOrderNo/{orderNo}")
    public R<OrderInfo> getByOrderNo(@PathVariable String orderNo) {
        OrderInfo orderInfo = orderInfoService.getByOrderNo(orderNo);
        return R.ok(orderInfo);
    }
}

